<template>
  <div>
    <ve-pie v-if="name !== '网售'" :data="channelTypeData" :events="chartEvents"></ve-pie>
    <ve-pie v-else :data="channelData" :events="chartEvents"></ve-pie>
  </div>
</template>

<script>
import $api from "@/api/api-charts";
import DateTime from "@/utils/DateTime";

export default {
  name: "PieChannelOrder",
  data: function () {
    let self = this;
    let chartEvents = {
      click(e) {
        self.chartClickHandler(e);
      }
    };
    return {
      channelTypeData: {
        columns: ['渠道', '交易金额'],
        rows: []
      },
      channelData: {
        columns: ['name', 'value'],
        rows: []
      },
      name: '',
      chartEvents,
      params: {
        tenantName: '',
        cinemaName: '',
        channelTypeName: '',
        channelName: '',
        orderYear: '',
        orderMonth: '',
        orderDay: '',
        orderHour: '',
        datetimeStart: DateTime.of().toDateTimeStart(),
        datetimeEnd: DateTime.of().toDateTimeEnd()
      }
    }
  },
  created() {
    $api.chartsChannelTypeOrder(this.params).then(data => this.channelTypeData = data);
    $api.chartsChannelOrder(this.params).then(data => this.channelData = data);
  },
  methods: {
    chartClickHandler(e) {
      this.name = e.name;
    }
  }
}
</script>

<style scoped>

</style>
